<%-- 
    Document   : joinRequests
    Created on : Dec 9, 2011, 6:13:53 AM
    Author     : Michael
--%>

<%@page import="java.sql.*"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<% if(session.getAttribute("LoggedIn")==null)
       {
    response.sendRedirect("index.html");
    return;
        }

%>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
        <title>Requests</title>
    </head>
    <body>
        <input type="button" value="Home" onclick="window.location='gohome.jsp'"/>&nbsp;
  <input type="button" value="Log Out" onclick="window.location='logout.jsp'"/>
        <table width="600" border="1">
            <tr><td>        <h1>Requests</h1></td></tr>
            
                
                <%
                Connection conn = null;
                try
                {
                    conn = new DBClasses.GetConnection().getConnection();
                    String query = "SELECT t.CustomerID, Concat(cu.Firstname, ' ', cu.Lastname) AS Name, t.CircleID, ci.CircleName " +
                            "FROM tentatives t, customer cu, circle ci WHERE t.CustomerID=cu.CustomerID AND t.CircleID=ci.CircleID " +
                            "AND t.CircleOwner=" + session.getAttribute("UserID") + " AND t.OwnerApproved=0";
                    ResultSet rs = conn.createStatement().executeQuery(query);
%>
                        <tr><td><h3>To Join</h3></td></tr>
                        <tr><td>Username</td> <td>Circle</td></tr>
                        <% while(rs.next()) { %>
                        <tr>
                            <form name="accept1" action="AddUserTentative.jsp" method="post">
                            <input type="hidden" name="PERS" value="<%=rs.getInt("t.CustomerID")%>" />
                            <input type="hidden" name="CIRC" value="<%=rs.getInt("t.CircleID")%>" />
                            <td width="200"><%=rs.getString("Name")%></td>
                            <td><%=rs.getString("ci.CircleName")%></td>
                            <td><input type="button" onclick="document.accept1.submit()" value="Accept"/></td>
                            </form>
                        </tr>
                        <% } query = "SELECT t.CustomerID, Concat(cu.Firstname, ' ', cu.Lastname) AS Name, t.CircleID, ci.CircleName " +
                            "FROM tentatives t, customer cu, circle ci WHERE t.CustomerID=" + session.getAttribute("UserID") +" AND t.CircleID=ci.CircleID " +
                            "AND t.CircleOwner=cu.CustomerID AND t.CustomerApproved=0";
                             rs = conn.createStatement().executeQuery(query);
%>
                        <tr><td><h3>For You To Join</h3></td></tr>
                        <tr><td>Owner</td> <td>Circle</td></tr>
                        <% while(rs.next()) { %>
                        <tr>
                            <form name="accept1" action="AddUserTentative.jsp" method="post">
                            <input type="hidden" name="PERS" value="<%=rs.getInt("t.CustomerID")%>" />
                            <input type="hidden" name="CIRC" value="<%=rs.getInt("t.CircleID")%>" />
                            <td width="200"><%=rs.getString("Name")%></td>
                            <td><%=rs.getString("ci.CircleName")%></td>
                            <td><input type="button" onclick="document.accept1.submit()" value="Accept"/></td>
                            </form>
                        </tr>
                    


                
        </table>

        
                
                <%
                                } }
                
                catch(Exception e)
                                               {
                    e.printStackTrace();
                }
                finally
                {
                    try{ conn.commit();
                    conn.close();
                    }
                    catch(Exception e)
                    {
                        e.printStackTrace();
                  }
                }
                
                %>

    </body>
</html>
